package io.wdb.wxapp.model;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import org.springframework.util.ObjectUtils;

import com.google.gson.Gson;

import io.wdb.common.utils.DateUtils;
import io.wdb.modules.activity.wxapp.entity.HdLotteryActivityConvertInfoEntity;
import io.wdb.modules.activity.wxapp.entity.HdLotteryActivityEntity;
import io.wdb.modules.activity.wxapp.entity.HdLotteryUserInfoEntity;
import io.wdb.modules.activity.wxapp.entity.HdUserEntity;
import io.wdb.modules.activity.wxapp.service.HdLotteryActivityService;
import io.wdb.modules.activity.wxapp.service.HdUserService;

public class HdLotteryUserInfoModel implements Serializable{

	private static final long serialVersionUID = -6784393436295551038L;
	private String headImg;
	private String loterryName;
	private String createTime;
	private String nickName;
	public String getHeadImg() {
		return headImg;
	}
	public void setHeadImg(String headImg) {
		this.headImg = headImg;
	}
	public String getLoterryName() {
		return loterryName;
	}
	public void setLoterryName(String loterryName) {
		this.loterryName = loterryName;
	}
	public String getCreateTime() {
		return createTime;
	}
	public void setCreateTime(String createTime) {
		this.createTime = createTime;
	}
	public String getNickName() {
		return nickName;
	}
	public void setNickName(String nickName) {
		this.nickName = nickName;
	}
	
	public static HdLotteryUserInfoModel convert(HdLotteryActivityConvertInfoEntity entity) {
		
		HdLotteryUserInfoModel model = new HdLotteryUserInfoModel();
		if(ObjectUtils.isEmpty(entity)) {
			return model;
		}
		model.setCreateTime(DateUtils.format(entity.getCreateTime(),DateUtils.DATE_PATTERN));
		model.setHeadImg(entity.getAvatar());
		model.setNickName(entity.getNickname());
		model.setLoterryName(entity.getLotteryContent().split(";")[0]);
		
		return model;
	}
	
	public static List<HdLotteryUserInfoModel> convert(List<HdLotteryActivityConvertInfoEntity> entities) {
		List<HdLotteryUserInfoModel> models = new ArrayList<HdLotteryUserInfoModel>();
		if(ObjectUtils.isEmpty(entities) || entities.size() == 0) {
			return models;
		}
		for(HdLotteryActivityConvertInfoEntity entity:entities) {
			if(!entity.getLotteryName().contains("继续")) {
				
				models.add(convert(entity));
			}
		}
		return models;
	}
	
	@Override
	public String toString() {
		return new Gson().toJson(this);
	}
}
